package com.springboot.demo.event.controller;

import com.springboot.demo.event.User;
import com.springboot.demo.event.UserRegisterEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.util.ClassUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedType;
import java.util.Arrays;

@RestController
@RequestMapping("/listener")
public class UserController {
    @Autowired
    ApplicationContext applicationContext;

    @Autowired
    User userpost;

    @GetMapping
    public void request() {
        System.out.println("执行业务代码");
        applicationContext.publishEvent(new UserRegisterEvent(this, new User(10086,"移动")));
        /*
        * 测试ClassUtils*/
        String className = "com.springboot.demo.event.User";
        boolean present = ClassUtils.isPresent(className, null);
        System.out.println(className + "是否存在:"+present);

        Class<?> aClass = ClassUtils.resolveClassName(className, null);
        Annotation[] annotatedInterfaces = aClass.getAnnotations();
        System.out.println(Arrays.toString(annotatedInterfaces));

        System.out.println(userpost);
    }
}
